﻿using AutoMapper;
using MediatR;
using S.Parturition.Domain.Model;
using S.Parturition.Infrastructure.Interface;
using S.Parturition.Read.API.Application.Command;

namespace S.Parturition.Read.API.Application.CommandHandlers
{
    public class GetLambByIdHandler : IRequestHandler<GetLambByIdCommand, LambRegistrationModel>
    {

        private readonly ILambRegistrationRepository lambRegistration;

        private readonly IMapper mapper;

        public GetLambByIdHandler(ILambRegistrationRepository lambRegistration, IMapper mapper)
        {
            this.lambRegistration = lambRegistration;
            this.mapper = mapper;
        }

        public async Task<LambRegistrationModel> Handle(GetLambByIdCommand request, CancellationToken cancellationToken)
        {
            return lambRegistration.GetAllAsync().Result.Where(x => x.EarTag == request.EarTag).FirstOrDefault();
        }
    }
}
